package game.component;

import math.Maths;
import math.vector.vec3f;

public class Rotation 
{
    
    private vec3f rots; // rotations, stored as (pitch, yaw, roll)
    public vec3f rots()
    {
        return rots;
    }
    
    private vec3f cosRots;
    public vec3f cosRots()
    {
        return cosRots;
    }
    
    private vec3f sinRots;
    public vec3f sinRots()
    {
        return sinRots;
    }
    
    private vec3f dirLook; // Direction vector created by rotation angles
    public vec3f dirLook()
    {
        return dirLook;
    }
    
    private vec3f rotsStart;
    public vec3f rotsStart()
    {
        return rotsStart;
    }
    
    public Rotation() 
    {
        rots = new vec3f();
        cosRots = new vec3f();
        sinRots = new vec3f();
        
        dirLook = new vec3f();
        
        rotsStart = new vec3f();
    }
    
    public void update(float dXRot, float dYRot, float dZRot) 
    {
        rots.x += dXRot;
        rots.y += dYRot;
        rots.z += dZRot;
        
        cosRots.x = Maths.cosRad(rots.x);
        sinRots.x = Maths.sinRad(rots.x);
        cosRots.y = Maths.cosRad(rots.y);
        sinRots.y = Maths.sinRad(rots.y);
        cosRots.z = Maths.cosRad(rots.z);
        sinRots.z = Maths.sinRad(rots.z);
        
        dirLook.x = sinRots.y * cosRots.x;
        dirLook.y = sinRots.x;
        dirLook.z = -cosRots.y * cosRots.x;
    }

    public void setStart(float pitchAngleRad, float yawAngleRad, float tiltAngleRad) 
    {
        rotsStart = new vec3f(pitchAngleRad, yawAngleRad, tiltAngleRad);
        this.reset();
    }
    
    public void setStart(vec3f rotsRad) 
    {
        this.setStart(rotsRad.x, rotsRad.y, rotsRad.z);
    }
    
    public void reset() 
    {
        rots.setTo(rotsStart);
    }
    
    public String toString() 
    {
        String s = "";
        s += "ROTATION COMPONENT";
        s += "\n   rots: " + rots;
        s += "\n   dirLook: " + dirLook;
        return s;
    }
    
}
